<?
if(! defined('BASEPATH') ){ exit('Unable to view file.'); }
$users = $db->GetNumRows($db->Query("SELECT id FROM `users`"));
$banned = $db->GetNumRows($db->Query("SELECT id FROM `users` WHERE `banned`='1'"));
$coins = $db->GetNumRows($db->Query("SELECT id FROM `transactions` WHERE `type`='0'"));
$vip = $db->GetNumRows($db->Query("SELECT id FROM `transactions` WHERE `type`='1'"));

$sql = $db->Query("SELECT type, SUM(money) FROM transactions GROUP BY type");
while($row = $db->FetchArray($sql)){
	if($row['type'] == "0"){
		$income_coins = $row['SUM(money)'];
	}elseif($row['type'] == "1"){
		$income_vip = $row['SUM(money)'];
	}
}

$a_google = $db->GetNumRows($db->Query("SELECT id FROM `sites`"));
$a_facebook = $db->GetNumRows($db->Query("SELECT id FROM `facebook`"));
$a_twitter = $db->GetNumRows($db->Query("SELECT id FROM `twitter`"));
$a_surf = $db->GetNumRows($db->Query("SELECT id FROM `surf`"));
$a_youtube = $db->GetNumRows($db->Query("SELECT id FROM `youtube`"));
$i_google = $db->GetNumRows($db->Query("SELECT id FROM `sites` WHERE `banned`>'0'"));
$i_facebook = $db->GetNumRows($db->Query("SELECT id FROM `facebook` WHERE `active`>'0'"));
$i_twitter = $db->GetNumRows($db->Query("SELECT id FROM `twitter` WHERE `active`>'0'"));
$i_surf = $db->GetNumRows($db->Query("SELECT id FROM `surf` WHERE `active`>'0'"));
$i_youtube = $db->GetNumRows($db->Query("SELECT id FROM `youtube` WHERE `active`>'0'"));

$a_youtubesub = $db->GetNumRows($db->Query("SELECT id FROM `ytsubs`"));
$i_youtubesub = $db->GetNumRows($db->Query("SELECT id FROM `ytsubs` WHERE `active`>'0'"));

$a_tweets = $db->GetNumRows($db->Query("SELECT id FROM `tweet`"));
$i_tweets = $db->GetNumRows($db->Query("SELECT id FROM `tweet` WHERE `active`>'0'"));

$a_stumble = $db->GetNumRows($db->Query("SELECT id FROM `stumbleupon`"));
$i_stumble = $db->GetNumRows($db->Query("SELECT id FROM `stumbleupon` WHERE `active`>'0'"));

$tot_clicks1 = $db->FetchArray($db->Query("SELECT SUM(visits) AS sum_visits FROM sites"));
$tot_clicks2 = $db->FetchArray($db->Query("SELECT SUM(likes) AS sum_visits FROM facebook"));
$tot_clicks3 = $db->FetchArray($db->Query("SELECT SUM(earned) AS sum_visits FROM twitter"));
$tot_clicks4 = $db->FetchArray($db->Query("SELECT SUM(visits) AS sum_visits FROM surf"));
$tot_clicks5 = $db->FetchArray($db->Query("SELECT SUM(views) AS sum_visits FROM youtube"));

$tot_clicks7 = $db->FetchArray($db->Query("SELECT SUM(visits) AS sum_visits FROM tweet"));
$tot_clicks8 = $db->FetchArray($db->Query("SELECT SUM(earned) AS sum_earned FROM ytsubs"));
$tot_clicks9 = $db->FetchArray($db->Query("SELECT SUM(visits) AS sum_visits FROM stumbleupon"));

$tot_clicks  = $tot_clicks1['sum_visits']+$tot_clicks2['sum_visits']+$tot_clicks3['sum_visits']+$tot_clicks4['sum_visits']+$tot_clicks5['sum_visits']+$tot_clicks7['sum_visits']+$tot_clicks8['sum_earned']+$tot_clicks9['sum_earned'];

?>
            <div id="page-subheader">
                <div class="wrapper clearfix">
                    <nav id="sub-nav">
                        <ul>
                            <li class="active"><a href="index.php">Summary</a></li>
							<li><a href="index.php?x=sales">Sales</a></li>
                        </ul>
                    </nav>
                </div>
            </div>
        </header>
        <section id="content">
            <div class="wrapper">
                <section class="grid_6 first top">
                    <div class="columns">
                        <div class="column grid_3 first">
                            <div class="widget collapsible">
                                <header><h2>Total Clicks: <a href="#"><?=$tot_clicks?></a></h2></header>
                                <section>
                                    <table class="no-style full">
                                        <tbody>
                                            <tr>
                                                <td>Facebook</td>
                                                <td style="width:70%"><div id="progress1" class="progress progress-green"><span style="width: <?= @percent($tot_clicks2['sum_visits'], $tot_clicks)?>%;"><b><?= @percent($tot_clicks2['sum_visits'], $tot_clicks)?>%</b></span></div></td>
                                                <td style="width:40px" class="ar"><?=$tot_clicks2['sum_visits']?></td>
                                            </tr>
                                            <tr>
                                                <td>Google</td>
                                                <td><div class="progress progress-blue"><span style="width: <?= @percent($tot_clicks1['sum_visits'], $tot_clicks)?>%;"><b><?= @percent($tot_clicks1['sum_visits'], $tot_clicks)?>%</b></span></div></td>
                                                <td class="ar"><?=$tot_clicks1['sum_visits']?></td>
                                            </tr>
                                            <tr>
                                                <td>Twitter</td>
                                                <td><div class="progress progress-orange"><span style="width: <?= @percent($tot_clicks3['sum_visits'], $tot_clicks)?>%;"><b><?= @percent($tot_clicks3['sum_visits'], $tot_clicks)?>%</b></span></div></td>
                                                <td class="ar"><?=$tot_clicks3['sum_visits']?></td>
                                            </tr>
											<tr>
                                                <td>Youtube</td>
                                                <td><div class="progress progress-brown"><span style="width: <?= @percent($tot_clicks5['sum_visits'], $tot_clicks)?>%;"><b><?= @percent($tot_clicks5['sum_visits'], $tot_clicks)?>%</b></span></div></td>
                                                <td class="ar"><?=$tot_clicks5['sum_visits']?></td>
                                            </tr>
											<tr>
                                                <td>Digg</td>
                                                <td><div class="progress progress-blue"><span style="width: <?= @percent($tot_clicks6['sum_visits'], $tot_clicks);?>%;"><b><?= @percent($tot_clicks6['sum_visits'], $tot_clicks);?>%</b></span></div></td>
                                                <td class="ar"><?= $tot_clicks6['sum_visits'];?></td>
                                            </tr>
											<tr>
                                                <td>Auto Surf</td>
                                                <td><div class="progress progress-red"><span style="width: <?= @percent($tot_clicks4['sum_visits'], $tot_clicks)?>%;"><b><?= @percent($tot_clicks4['sum_visits'], $tot_clicks)?>%</b></span></div></td>
                                                <td class="ar"><?=$tot_clicks4['sum_visits']?></td>
                                            </tr>
											<tr>
                                                <td>Twitter Tweets</td>
                                                <td><div class="progress progress-green"><span style="width: <?= @percent($tot_clicks7['sum_visits'], $tot_clicks)?>%;"><b><?= @percent($tot_clicks7['sum_visits'], $tot_clicks)?>%</b></span></div></td>
                                                <td class="ar"><?=$tot_clicks7['sum_visits']?></td>
                                            </tr>
											<tr>
                                                <td>YouTube Subscribers</td>
                                                <td><div class="progress progress-orange"><span style="width: <?= @percent($tot_clicks7['sum_earned'], $tot_clicks)?>%;"><b><?= @percent($tot_clicks8['sum_earned'], $tot_clicks)?>%</b></span></div></td>
                                                <td class="ar"><?=$tot_clicks8['sum_earned']?></td>
                                            </tr>
											<tr>
                                                <td>StumbleUpon Followers</td>
                                                <td><div class="progress progress-orange"><span style="width: <?= @percent($tot_clicks9['sum_visits'], $tot_clicks)?>%;"><b><?= @percent($tot_clicks9['sum_visits'], $tot_clicks)?>%</b></span></div></td>
                                                <td class="ar"><?=$tot_clicks9['sum_earned']?></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </section>
                            </div>
                        </div>

                        <div class="column grid_3 last">
						    <div class="widget collapsible">
                                <header><h2>Users Statistics</h2></header>
                                <section>
                                    <table class="no-style full">
                                        <tbody>
                                            <tr>
                                                <td>Total Users</td>
                                                <td class="ar"><a href="index.php?x=users"><?=$users?></a></td>
                                            </tr>
                                            <tr>
                                                <td>Active Users</td>
                                                <td class="ar"><a href="index.php?x=users"><?=($users - $banned)?></a></td>
                                            </tr>
                                            <tr>
                                                <td>Banned Users</td>
                                                <td class="ar"><a href="index.php?x=users"><?=$banned?></a></td>
                                            </tr>
                                        </tbody>
                                    </table>
                                </section>
                            </div>
							
                            <div class="widget collapsible">
                                <header><h2>Sales Statistics</h2></header>
                                <section>
                                    <table class="no-style full">
                                        <tbody>
                                            <tr>
                                                <td>Coins</td>
                                                <td class="ar"><a href="index.php?x=sales"><?=$coins?></a></td>
                                                <td class="ar"><?=($income_coins == "" ? "0.00" : $income_coins)?> $</td>
                                            </tr>
											<tr>
                                                <td>VIP</td>
                                                <td class="ar"><a href="index.php?x=sales"><?=$vip?></a></td>
                                                <td class="ar"><?=($income_vip == "" ? "0.00" : $income_vip)?> $</td>
                                            </tr>	
											<tr>
                                                <td>Total</td>
                                                <td class="ar"><a href="index.php?x=sales"><?=($coins+$vip)?></a></td>
                                                <td class="ar"><?=(($income_vip+$income_coins) == "" ? "0.00" : ($income_vip+$income_coins))?> $</td>
                                            </tr>												
                                        </tbody>
                                    </table>
                                </section>
                            </div>
                        </div>
                    </div>

                    <div class="clear">&nbsp;</div>
                </section>
				
                <aside class="grid_2 top">
                    <div class="accordion">
                        <header class="current"><h2>Active Websites</h2></header>
                        <section style="display:block">
                            <dl>
                                <dt>Facebook Likes</dt>
                                <dd><div class="progress progress-green"><span style="width: <?= @percent(($a_facebook - $i_facebook), $a_facebook)?>%;"><b><?=(($a_facebook - $i_facebook).'/'.$a_facebook)?></b></span></div></dd>
                                <dt>Google 1+</dt>
                                <dd><div class="progress progress-blue"><span style="width: <?= @percent(($a_google - $i_google), $a_google)?>%;"><b><?=(($a_google - $i_google).'/'.$a_google)?></b></span></div></dd>
                                <dt>Twitter Followers</dt>
                                <dd><div class="progress progress-orange"><span style="width: <?= @percent(($a_twitter - $i_twitter), $a_twitter)?>%;"><b><?=(($a_twitter - $i_twitter).'/'.$a_twitter)?></b></span></div></dd>
								<dt>Youtube Views</dt>
                                <dd><div class="progress progress-brown"><span style="width: <?= @percent(($a_youtube - $i_youtube), $a_youtube)?>%;"><b><?=(($a_youtube - $i_youtube).'/'.$a_youtube)?></b></span></div></dd>
								<dt>Digg</dt>
                                <dd><div class="progress progress-blue"><span style="width: <?= @percent(($a_digg - $i_digg), $a_digg);?>%;"><b><?=(($a_digg - $i_digg).'/'.$a_digg)?></b></span></div></dd>
								<dt>Auto Surf</dt>
                                <dd><div class="progress progress-red"><span style="width: <?= @percent(($a_surf - $i_surf), $a_surf)?>%;"><b><?=(($a_surf - $i_surf).'/'.$a_surf)?></b></span></div></dd>
								<dt>YouTube Subscribers</dt>
                                <dd><div class="progress progress-green"><span style="width: <?= @percent(($a_youtubesub - $i_youtubesub), $a_youtubesub)?>%;"><b><?=(($a_youtubesub - $i_youtubesub).'/'.$a_youtubesub)?></b></span></div></dd>
                          								<dt>Twitter Tweets</dt>
                               
							   <dd><div class="progress progress-blue"><span style="width: <?= @percent(($a_tweets - $i_tweets), $a_tweets)?>%;"><b><?=(($a_tweets - $i_tweets).'/'.$a_tweets)?></b></span></div></dd>
            <dt>StumbleUpon Followers</dt>
                                <dd><div class="progress progress-orange"><span style="width: <?= @percent(($a_stumble - $i_stumble), $a_stumble)?>%;"><b><?=(($a_stumble - $i_stumble).'/'.$a_stumble)?></b></span></div></dd>
                          		 


			 </dl>
                        </section>
                    </div>
                </aside>
                <div class="clear"></div>

            </div>
            <div id="push"></div>
        </section>
    </div>
    
    <footer id="page-footer">
        <div id="footer-inner">
            <p class="wrapper">All rights reserved &copy; <a href="http://mafianet.org" target="_blank">MafiaNet</a> <?=date('Y')?></p>
        </div>
    </footer>
</body>
</html>